package com.fashion.utils;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * User: juventus
 * Date: 11-5-31
 * Time: 下午5:13
 */
public class JsonUtils {
    public static String parseCollection(Collection collection, List<String> excludes) {
        JsonConfig config = new JsonConfig();
        config.setIgnoreDefaultExcludes(false);
        config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        String[] excludeArray = new String[excludes.size()];
        excludes.toArray(excludeArray);
        config.setExcludes(excludeArray);
        config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor(null));
        JSONArray newsList = JSONArray.fromObject(collection, config);

        return newsList.toString();
    }
}
